package
{
	import Common.BitmapSprite;
	import Common.GameTimer;
	
	import Sync.SyncSystem;
	
	import Tools.Input;
	
	import entity.Entity;
	import entity.EntityManager;
	
	import flash.display.*;
	import flash.events.Event;
	import flash.text.*;
	import flash.utils.*;
	
	import logic.GameLogic;
	
	public class Main extends Sprite
	{
		private var gt:GameTimer;
		private var pt:GameTimer;
		private var input:Input;
		private var txt:TextField;
		
		public function Main()
		{
			txt = new TextField();
			txt.x = 100;
			txt.width = 1000;
			stage.addChild(txt);
			
			stage.scaleMode = StageScaleMode.NO_SCALE;
			var syncSys:SyncSystem = SyncSystem.getInstance();
			syncSys.connectToServer("122.49.29.164", 3666);
			
			Input.getInstance().initialize(this.stage);
			EntityManager.getInstance().initialize(this);
			
			gt = new GameTimer(15, update);
			
			pt = new GameTimer(1000, ping);
		}
		
		public function update(delta:int):void
		{
		
			var syncSys:SyncSystem = SyncSystem.getInstance();
			syncSys.step();

			
			if (SyncSystem.getInstance().isConnected())
			{
				txt.text = "已连接服务器";
			}
			else
			{
				txt.text = "未连接服务器";
			}
			
			txt.appendText("      玩家数:" + GameLogic.getInstance().getPlayerCount());
			txt.appendText("      PING:" + GameLogic.getInstance().getPingValue() + "ms");
		}
		
		public function ping(delta:int):void
		{
			GameLogic.getInstance().ping();
		}
		

	}
}